---
title: HuggingFaceInference
---

Here's an example of calling a HugggingFaceInference model as an LLM:

```bash npm
npm install @langchain/community @langchain/core @huggingface/inference@4
```

import UnifiedModelParamsTooltip from "/snippets/javascript-integrations/unified-model-params-tooltip.mdx";

<UnifiedModelParamsTooltip />

```typescript
import { HuggingFaceInference } from "@langchain/community/llms/hf";

const model = new HuggingFaceInference({
  model: "gpt2",
  apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.HUGGINGFACEHUB_API_KEY
});
const res = await model.invoke("1 + 1 =");
console.log({ res });
```

## Related

- LLM [conceptual guide](/oss/concepts/text_llms)
- LLM [how-to guides](/oss/how-to/#llms)
